package cn.larry.spring;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class ValueDemo {
	@Value("${jdbc.driverClass}")
	private String driver;

	@Value("#{anotherObj.name}")
	private String name;

	// @Value("${ '#{anotherObj.media}' }") //这个不支持。
	@Value("#{ '${media}' }") // ok
	private String media;

	// @Value("${noExist:noExist~}") // ok
	@Value("${noExist:'noExist~  ~~'}") // ok
	private String demo;

	// @Value("#{anotherObj.noKey?:noKey is null}") //error
	// @Value("#{anotherObj.noKey?:anotherObj.media}") //ok
	@Value("#{anotherObj.noKey?:'anotherObj.noKey is null'}") // ok
	private String demo2;

	@PostConstruct
	public void run() {
		System.out.println(driver);
		System.out.println(name);
		System.out.println(media);
		System.out.println(demo);
		System.out.println(demo2);
	}

}
